<!-- 目标审核 -->
<template>
  <div class='target_examine'>
    <Row type='flex' justify="end">
      <Col span="3" class="total_num">
      <Button type="primary" @click="exportFun()" style="margin-left: 8px"
        :disabled="pageData.total==0" v-if="unlocking('0107070302')">导出</Button>
      </Col>
    </Row>
    <Tabs v-model="curState" type="card" :animated="false" @on-click="onChangeTab">
      <TabPane label="待审核" name="waitAudit"></TabPane>
      <TabPane label="已通过" name="passAudit"></TabPane>
      <TabPane label="已驳回" name="rejectAudit"></TabPane>
    </Tabs>
    <dt-grid ref="table" :columns="columns" :list="tableData" />
    <page :pageData="pageData" @pageOnChangeFun="pageOnChangeFun"
      @pageOnPageSizeChangeFun="pageOnPageSizeChangeFun"></page>
    <!--周目标详情-->
    <Modal v-model="weekPageFlag" title="周目标详情" width="70%" :footer-hide="true"
      class="target-modal" @on-cancel="closeDetail">
      <detail-week-page v-if="weekPageFlag" @onClose="closeDetail" @Audit='init'>
      </detail-week-page>
    </Modal>
  </div>
</template>

<script>
  import columnsAll from './components/common/examineHead'
  import examineApi from '@/biz/synthetic/examineFitClass'
  import detailWeekPage from './components/common/detailWeekPage.vue'
  import dt from '@dt/dt'

  export default {
    components: { detailWeekPage },
    data() {
      return {
        curState: 'waitAudit',
        odlState: 'waitAudit',
        columns: [],
        pageData: {
          total: 0,
          current: 1,
          rows: 10,
          pageSizeOpts: [10, 20, 30, 40, 50],
        },
        tableData: [],
        weekPageFlag: false,
      }
    },
    methods: {
      onChangeTab(val) {
        if (this.odlState == val) return false
        this.odlState = val
        this.init()
      },
      init() {
        this.closeDetail()
        this.$refs.table.loading = true
        let requestDate = this.$tool.dateFtt('yyyy-MM-dd hh:mm:ss', new Date())
        let params = {
          pageNum: this.pageData.current,
          pageSize: this.pageData.rows,
          data: {
            auditFlag: this.curState,
            buildingId: this.$dt.buildInfo().housesId,
          },
          requestDate,
        }
        examineApi
          .weekAuditPage(params)
          .then((res) => {
            this.$refs.table.loading = false
            this.tableData = res.list
            this.pageData.total = Number(res.total)
          })
          .catch(() => {
            this.$refs.table.loading = false
          })
      },
      //分页触发
      pageOnChangeFun(pages) {
        this.init()
      },
      //改变每页条数触发
      pageOnPageSizeChangeFun(rows) {
        this.init()
      },
      //导出
      exportFun() {
        let requestDate = this.$tool.dateFtt('yyyy-MM-dd hh:mm:ss', new Date())
        let params = {
          pageNum: this.pageData.current,
          pageSize: this.pageData.rows,
          data: {
            auditFlag: this.curState,
            buildingId: this.$dt.buildInfo().housesId,
          },
          requestDate,
        }
        examineApi.exportWeekAudit(params).then((res) => {})
      },
      closeDetail() {
        this.weekPageFlag = false
      },
      ivewAudit(data) {
        console.log(data)
        let params = {
          operateType: 0, // 用于区分0，查看,1，新增,2，调整 ,
          periodId: data.row.periodId, // 查看 调整时需用的key
          isShowExamine: data.type == 2 ? true : false, // 是否展示审核按钮
          activedMonth: data.row.monthDesc, // 第几月
          auditStep: 'weekAudit',
          headerInfo: {
            buildingName: this.$dt.buildInfo().housesName,
            rangePeriod: data.row.monthDesc,
            createDate: data.row.createDate,
            auditStatus: data.row.auditStatus,
          },
        }
        dt.memory.set('weekTarget_params', params)
        Object.keys(params).length && dt.session.set('weekTarget_params', params)
        this.weekPageFlag = true
      },
    },
    created() {},
    mounted() {
      this.columns = columnsAll.targetColumns(this)
      this.init()
    },
  }
</script>
<style lang='scss' scoped>
  .target_examine {
    padding: 20px;
  }
</style>